package action;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sun.org.apache.bcel.internal.generic.NEWARRAY;

import bean.Donate;

import dao.DonateDao;

public class DonateServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String page = req.getParameter("page");
		DonateDao dd = new DonateDao();
		ArrayList<Donate> donate_list = dd.getAllDonate();
		HttpSession session = req.getSession();
		session.setAttribute("donate_list", donate_list);
		ArrayList<Donate> donate_list1 = new ArrayList<Donate>();
		for (int i = 0; i < donate_list.size() && i < 10; i++) {
			donate_list1.add(donate_list.get(i));
		}
		session.setAttribute("donate_list1", donate_list1);
		
		session.setAttribute("donate_total_items", donate_list.size());
		int num = donate_list.size() % 25;
		int donate_total_pages = (num == 0 ? donate_list.size() / 25
				: donate_list.size() / 25 + 1);
		session.setAttribute("donate_total_pages", donate_total_pages);
		session.setAttribute("donate_current_page", 1);

		resp.sendRedirect("separateDonate?page=" + page);
	}
}
